//These mirror the calls that are available on the resource-side of the backend
var apiURI = "http://localhost:8080/webappz-gu/api/";

function getURLParameter(name) {
    return decodeURIComponent((new RegExp('[?|&]' + name + '=' + '([^&;]+?)(&|#|;|$)').exec(location.search) || [, ""])[1].replace(/\+/g, '%20')) || null;
}

function getUsers() {
    return $.getJSON(apiURI + "user");
}

function getUser(user_id) {
    return $.getJSON(apiURI + "user/" + user_id);
}

function getSingleRun(user_id, run_id) {
    return $.getJSON(apiURI + "user/" + user_id + "/run/" + run_id);
}

function getRuns(user_id) {
    return $.getJSON(apiURI + "user/" + user_id + "/run");
}

function getTracks(user_id) {
    return $.getJSON(apiURI + "user/" + user_id + "/track");
}

function getRunsByTrack(user_id, track_name) {
    return $.getJSON(apiURI + "user/" + user_id + "/track/" + track_name);
}

function getFrames(user_id, run_id) {
    return $.getJSON(apiURI+"user/"+user_id+"/run/"+run_id+"/frame");
}

function updateUser(user_id, username, password, avatar, Givenname, Familyname, email) {
    return $.ajax({
        type: "PUT",
        url: apiURI + "user/" + user_id,
        data: {username: username,
            password: password,
            avatar: avatar,
            givenName: Givenname,
            familyName: Familyname,
            email: email

        }
    });
}
    
function removeRun(user_id, run_id) {
     return $.ajax({
        type: "DELETE",
        url: apiURI + "user/" + user_id + "/run/" + run_id
     });

}



